$(function(){
let row = document.querySelector('.row')
fetch('http://chst.vip:1234/api/getindexmenu')
.then(body=>body.json())
.then(res=>{
    let result = res.result
    console.log(res);
    let nav=''
    result.forEach(item => {
      
       let regExp = /^<[^<]+\s+src="([^''""]*)"/
            let r=item.img.match(regExp)
       nav+=`
       <div class="col-xs-3">
           <a href="#">
               <span>
                   <img data-name=${item.name} src="http://chst.vip:8081/mmb/${r[1]}" alt="">
               </span>
           </a>
           <p class="in_name">
               ${item.name}
           </p>
       </div>
         `
    });

    row.innerHTML=nav

    $("#nav>.container>.row>.col-xs-3").eq(7).click(function () {
        $(this).nextAll().slideToggle(200)
    })
    $('#nav>.container>.row>.col-xs-3').eq(0).click(function(){
        location.href='./pages/bjsearch.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(1).click(function(){
        location.href='./pages/saveMoney.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(2).click(function(){
        location.href='./pages/discount.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(3).click(function(){
        location.href='./pages/baicaijia.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(4).click(function(){
        location.href='./pages/htdiscount.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(5).click(function(){
        location.href='./pages/Coupons.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(6).click(function(){
        location.href='./pages/history.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(8).click(function(){
        location.href='./pages/item.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(9).click(function(){
        location.href='./pages/rank.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(10).click(function(){
        location.href='./pages/navigation.html'
    })
    $('#nav>.container>.row>.col-xs-3').eq(11).click(function(){
        location.href='./pages/brand.html'
    })

})
let list = document.querySelector('.list')
let ele = ''
fetch('http://chst.vip:1234/api/getmoneyctrl')
.then(body=>body.json())
.then(res=>{
    console.log(res);
    res.result.forEach(item=>{
        let regExp = /(?<=imgurl=)[^'"]*/
        let r=item.productImg2.match(regExp)
        
        ele+= `
        <li productid=${item.productId}>
            <img src="${r[0]}" alt="">
            <div>
                <p>${item.productName} <span>${item.productPinkage}</span></p >
                <div>
                    <span>${item.productFrom}|${item.productTime}</span>
                    <div>
                        <span class="iconfont .icon-pinglun"></span>
                        <span>${item.productComCount}</span>
                    </div>
                </div>
            </div>
        </li>
        `
    })

    list.innerHTML = ele



    let lis = document.querySelectorAll('.liebiao>.list>li')
    console.log(lis);
    
    for(var i=0;i<lis.length;i++){
        lis[i].onclick = function(){
            let id = this.getAttribute('productid')
            console.log(id);
    
            location.href = './pages/savemoneydetails.html?productid='+id
        }
    }
})
})